#

| Chapter 19 Creating and Reading Archives |

## 19.4 A Simple Version of unshar

This little script is a great example of how something simple in UNIX can do a lot. It skips past the mail header and comments that come before some shell archives (19.2), then feeds the archive to a shell. You can use it while you're reading a message with most UNIX mail programs (1.33):

>     & save | unshar

or give it the name of an archive file on its command line:

>     % unshar somefile.shar

and so on. Here's a version of the script:

>     #! /bin/sh
>     # IGNORE LINES BEFORE FIRST "#" COMMENT STARTING IN FIRST COLUMN:
>     sed -n '/^#/,$p' $1 | sh

The script reads from its standard input or a single file. It skips all lines until the comment (`#`) that starts most shell archives; the rest of the lines are piped to the shell. It doesn't read from multiple files; that would add another couple of lines for a loop - and make the script too long! `:-)` In the last few years, much fancier unshar programs (19.3) have come out. They protect against "Trojan horses" buried in shar files and let systems without a Bourne shell (like DOS) unpack shell archives. This basic script still does a fine job though. [It also gives one more demonstration of why at least basic knowledge of sed (34.24) is so important to would-be power users. It's an incredibly handy utility. -TOR ]

- JP

19.3 unshar: Unarchive a Shell Archive |  | 19.5 Using tar to Create and Unpack Archives